import 'package:flutter/material.dart';

import '../../config/public_color.dart';

/// FileName dash_line
///
/// @Author lax
/// @Date 2023/3/31
///
/// @Description

class DashLine extends StatelessWidget {
  final double width;
  final double height;
  final double step;
  final double space;

  final Color? color;
  final EdgeInsets? margin;

  const DashLine({
    super.key,
    this.width = 100,
    this.height = 1,
    this.step = 4,
    this.space = 4,
    this.color,
    this.margin,
  });

  @override
  Widget build(BuildContext context) {
    if (width == 0 || height == 0) {
      return const SizedBox();
    }
    final axis = width > height ? Axis.horizontal : Axis.vertical;
    final count =
        width > height ? width / (step + space) : height / (step + space);
    return Container(
      margin: margin,
      width: width,
      height: height,
      child: ListView.separated(
        physics: const NeverScrollableScrollPhysics(),
        scrollDirection: axis,
        itemCount: count.toInt() + 1,
        itemBuilder: (context, index) {
          return SizedBox(
            width: axis == Axis.horizontal ? step : width,
            height: axis == Axis.vertical ? step : height,
            child: DecoratedBox(decoration: BoxDecoration(color: color ?? PublicColor.divider)),
          );
        },
        separatorBuilder: (context, index) {
          return SizedBox(
            width: axis == Axis.horizontal ? space : width,
            height: axis == Axis.vertical ? space : height,
          );
        },
      ),
    );
  }
}
